<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%@ include file="/commons/commonEdit.jsp"%>
<%@ include file="/commons/validation.jsp"%>
<%@ include file="/commons/dateTime.jsp" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>抵冲</title>
<script type="text/javascript" src="${ctx}/scripts/jquery.js"></script>
<script language="JavaScript" type="text/javascript"
	src=".${ctx}/js/public.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common.js"></script>
<script language="JavaScript" src="${ctx}/scripts/show.js"></script>
<script language="JavaScript" type="text/javascript"
	src="${ctx}/scripts/global.js"></script>
	
<link href="${ctx}/styles/listTable.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/styles/grid.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="${ctx}/scripts/div/common.js"></script>
<script type="text/javascript" src="${ctx}/scripts/public.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common.js"></script>
<script type="text/javascript" src="${ctx}/scripts/ajaxException.js"></script>

<link href="${ctx}/styles/listTable.css" rel="stylesheet"
	type="text/css" />
<link href="${ctx}/styles/grid.css" rel="stylesheet" type="text/css" />

<link href="${ctx}/css/show.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/css/public.css" rel="stylesheet" type="text/css">
<link href="${ctx}/css/aux_window.css" rel="stylesheet" type="text/css">


<script type="text/javascript">

	function saveWin(){ 
			var periodSelected = $("#payDate").val();
			var houseSelected = $("#houseNumber").val();
			var houseType = $("#houseType").val();
			
			
			if( ( houseSelected == "null" || houseSelected==null || houseSelected=="" ||houseSelected==undefined) ){
				Alert("单个房间抵冲时，房号不能为空！");
				return;
			}
			
			showLoading("抵冲操作正在进行，请稍候...");	
			jQuery.ajax({
					type:'GET',
					url	:"${ctx}/charge_preparePayAction.do?method=doOffset&houseNumber="+encodeURI(encodeURI(houseSelected))+"&payDate="+periodSelected+"&offsettype="+houseType,
					dataType:'text',
					success:function(result){
						if(result=="success"){
						 	SuccessAlert("抵冲完成！");
						 	windowClose('offsetIfm');
						}else if(result=="noSuchRoom"){
							hiddenLoading();
							FailureAlert("输入房号错误，请重新输入！");
						}else if(result=="noSchedule"){
							hiddenLoading();
							FailureAlert("请先设定该房间抵冲方案，并缴预交款，方可抵冲！");
						}else if(result=="invalidBalance"){
							hiddenLoading();
							FailureAlert("预交款余额不足，不能抵冲！");
						}else if(result=="noOffset"){
							hiddenLoading();
							FailureAlert("该房在选择的周期内早已完成抵冲，或者抵冲方案里的项目都没有欠费！");
						}else if(result=="noBalance"){
							hiddenLoading();
							FailureAlert("本房间不能（需）抵冲，请检查预交款与欲抵冲应缴金额！");
						}else if(result=="periodNoOffset"){
							hiddenLoading();
							FailureAlert("该房在选择的周期内不必抵冲！");
						}
					},
					error:function(error){
						hiddenLoading();
						FailureAlert('抵冲操作有误,请重试或与管理员联系！');
					}
				});
	}
	
	function setRoomStatus(status){
	 	var house = document.getElementById('houseNumber');
	 	var houseType = $("#houseType");
	 	
	 	if(status==0){
	 		house.value="全部";
	 		house.disabled=true;
	 		$("#houseType").val("0");
	 	}
	 	if(status==1){
	 		house.value="";
	 		house.disabled=false;
	 		$("#houseType").val("1");
	 	}
	 	
	}
</script>

</head>

<body >


	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	  <tr>
	    <td class="window_head_outBg">
	    <table border="0" cellpadding="0" cellspacing="0">
		      <tr><td><img src="${ctx}/images/ico_Advance.gif" width="16" height="16" align="absmiddle" /> <span class="window_head_intext">抵冲</span></td></tr>
	    </table>
	    </td>
	  </tr>
	  <tr><td class="aux_header_line_1"></td></tr>
	  <tr><td class="aux_header_line_2"></td></tr>
	  <tr>
	    <td class="content">

		<table width="100%" border="0" cellspacing="0" cellpadding="0">
	      <tr>
	        <td class="aux_outtable_color">
	        <table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color">
	            <tr>
	              <td class="aux_intable_td1"><input type="radio" name="offsettype" id="oneRoom" onclick="setRoomStatus(1)" value="1" checked>单个房间</td>
	              <td class="aux_intable_td2"><input type="radio" name="offsettype" id="allRoom" onclick="setRoomStatus(0)" value="0" >全部房间</td>
	            </tr>
	            <tr>
	              <td class="aux_intable_td1">房号：</td>
	              <td class="aux_intable_require" id="houseNumberTd">
	              		<input name="houseType" id="houseType" type="hidden" value="1"/>
	              		<input name="houseNumber" id="houseNumber" type="text" class="required"  size="16" validateMessage="房号不能为空" />
				  </td>
	            </tr>
	            <tr>
	              <td class="aux_intable_td1">缴费周期：</td>
	              <td class="aux_intable_require">
						<select id="payDate" name="payDate">
							<option value="0">全部</option>
							<c:forEach items="${periodDomainList}" var="period">
								<option value="${period.keyword }">${period.period}</option>
							</c:forEach>
						</select>
	              </td>
	              </tr>
	          </table>
	        </td>
	      </tr>
	    </table>

		</td>
	  </tr>
	  <tr>
	    <td class="window_footer"><table border="0" cellspacing="0" cellpadding="0">
	      <tr>
	        <td class="btn_between_space">&nbsp;</td>
	        <td><table border="0" cellpadding="0" cellspacing="0">
	            <tr>
	              <td class="buttonOffLeft" id="btn1_21"></td>
	              <td class="buttonOffMiddle" id="btn1_22" onClick="saveWin();" onMouseOver="btn_change_over(2)" onMouseOut="btn_change_out(2)" onBlur="btn_change(2)"><img src="${ctx}/images/ico_ok.gif" alt="" width="14" height="14" border="0" align="absbottom" /> 确 定</td>
	              <td class="buttonOffRight" id="btn1_23"></td>
	            </tr>
	        </table></td>
	        <td class="btn_between_space"></td>
	        <td><table border="0" cellpadding="0" cellspacing="0">
	            <tr>
	              <td class="buttonOffLeft" id="btn1_31"></td>
	              <td class="buttonOffMiddle" id="btn1_32" onClick="windowClose();" onMouseOver="btn_change_over(3)" onMouseOut="btn_change_out(3)" onBlur="btn_change(3)"><img src="${ctx}/images/ico_cancel.gif" alt="" width="14" height="14" border="0" align="absbottom" /> 关 闭</td>
	              <td class="buttonOffRight" id="btn1_33"></td>
	            </tr>
	        </table></td>
	      </tr>
	    </table></td>
	  </tr>
	</table>




</body>
</html>